﻿using System;
using Glue;
using Xunit;

namespace GlueExamples
{
    public class Fields
    {
        private readonly Mapping<DomainPerson, GuiPerson> mapping;

        private class GuiPerson
        {
            public String NameAsAField;
            public String ZipCode;
        }
        private class DomainPerson
        {
            public String NameAsAProperty { get; set; }
            public String ZipCode { get; set; }
        }

        public Fields()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
        }

        [Fact]
        public void Should_allow_relations_both_directions()
        {
            mapping.Relate(domain=>domain.NameAsAProperty,gui=>gui.NameAsAField);
        }

        [Fact]
        public void Should_not_autorelate_a_field_by_default()
        {
            mapping.AutoRelateEqualNames();
            Assert.Equal(0,mapping.Relations.Count);
        }

        [Fact]
        public void Should_autorelate_a_field_when_specified()
        {
            var autoRelateFields = true;
            mapping.AutoRelateEqualNames(false, autoRelateFields);
            Assert.Equal(1, mapping.Relations.Count);
        }

        [Fact]
        public void Should_not_fail_verification_on_fields()
        {
            mapping.GetRelationsVerification().AssertAllPropertiesRelated<GuiPerson>();
        }

    }
}
